﻿using System.Web.Mvc;
using SDF.Core;
using SDF.Core.Caching;
using SDF.Services.Configuration;
using SDF.Services.Localization;
using SDF.Services.Media;
using SDF.Services.Projects;
using SDF.Web.Framework.Controllers;
using SDF.Services.Security;
using SDF.Services.Helpers;
using SDF.Core.Infrastructure;
using SDF.Plugin.Misc.SAPAdapter.Models;

namespace SDF.Plugin.Misc.SAPAdapter.Controllers
{
    [AdminAuthorize]
    public class SAPAdapterController : SAPControlBase
    {
        private readonly IWorkContext _workContext;
        private readonly IProjectContext _projectContext;
        private readonly IProjectService _projectService;
        private readonly IPictureService _pictureService;
        private readonly ISettingService _settingService;
        private readonly ICacheManager _cacheManager;
        private readonly ILocalizationService _localizationService;
        private readonly IPermissionService _permissionService;
        private readonly IDateTimeHelper _dateTimeHelper;

        public SAPAdapterController(IWorkContext workContext,
            IProjectContext projectContext,
            IProjectService projectService,
            IPictureService pictureService,
            ISettingService settingService,
            ICacheManager cacheManager,
            ILocalizationService localizationService,
            IPermissionService permissionService,
            IDateTimeHelper dateTimeHelper)
        {
            this._workContext = workContext;
            this._projectContext = projectContext;
            this._projectService = projectService;
            this._pictureService = pictureService;
            this._settingService = settingService;
            this._cacheManager = cacheManager;
            this._localizationService = localizationService;
            this._permissionService = permissionService;
            this._dateTimeHelper = dateTimeHelper;
        }
        
        //[ChildActionOnly]
        public ActionResult Configure()
        {
            return View("~/Plugins/SDF.Plugin.Misc.SAPAdapter/Views/SAPInstance/List.cshtml", new SAPClientSearchModel());
        }
        
        public ActionResult ReCreateResource()
        {
            var plugin = EngineContext.Current.Resolve<SAPAdapterPlugin>();

            foreach (var dic in plugin._genResources())
            {
                plugin.AddOrUpdatePluginLocaleResource(dic.Key, dic.Value);
            }

            return Content("ok");
        }
    }
}